package cn.com.oyat.idea.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器
 * @Classname WebMvcConfigurer
 * @Date 2025/2/8 21:29
 * @Created by 87766867@qq.com
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**") // 对所有路径应用CORS配置
//                .allowedOrigins("*") // 允许的源
//                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的方法
//                .allowedHeaders("*") // 允许的头信息
//                .allowCredentials(true) // 是否允许证书传输（如cookies）
//                .maxAge(3600); // 预检请求的缓存时间（秒）
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器，并配置拦截路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") // 拦截 /home 路径
                .excludePathPatterns("/","/login","/idea/user/login","/static/**","/rpc/**");
    }
}
